// When DOM is ready
jQuery(document).ready(function(){
    jQuery("#client_login").fancybox({
        closeClick: false,
        autoScale: true,
        openEffect : 'elastic',
        closeEffect : 'elastic',
        padding: 0,
        centerOnScroll: true, 
        showNavArrows: true,
        href: "#loginbox"
    });
    // When the form is submitted
    jQuery("form#login").submit(function(){  
        if (jQuery("#agreed").attr("checked")!= "checked"&&(jQuery("#agreed").attr("checked")!=true))
        {
            alert(_login_agreed_term);
            return false;
        }
        // Hide 'Submit' Button
        jQuery('#submit').hide();
        jQuery('#login_error').hide();
        // Show Gif Spinning Rotator
        jQuery('#ajax_loading').show();
        // 'this' refers to the current submitted form  
        var str = jQuery(this).serialize();  
        // -- Start AJAX Call --
        jQuery.ajax({  
            type: "POST",
            url: "index.php", 
            data: str, 
            success: function(msg){  
                msg=ajax_string_dim(msg);
                // Show 'Submit' Button
                jQuery('#submit').show();
                // Hide Gif Spinning Rotator
                jQuery('#ajax_loading').hide();  
                if(msg == 'OK') // LOGIN OK?
                {  
                    //jQuery("form#login").html("<div class='login_box_success' style='display: block;'>"+jQuery(".login_box_success").html()+"</div>"); // Refers to 'status'
                    jQuery("form#login").html("");
                    jQuery("#loginbox .fancybox_title h4").html(jQuery(".login_box_success").html());
                    jQuery("#loginbox .fancybox_title").css("margin-bottom","0px");
                    // After 3 seconds redirect the 
                    setTimeout('go_to_private_page()', 2000); 
                }  
                else // ERROR?
                {  
                    var login_response = msg;
                    jQuery('#login_error').html(login_response).fadeToggle("normal");
                }  
            }  

        });  

        // -- End AJAX Call --

        return false;

    }); // end submit event

});

function go_to_private_page()
{
    window.location.reload(); // Members Area
}